import os
import random
import xml.etree.ElementTree as ET

from utils.utils import get_classes

VOCdevkit_path  = 'niaochao'
if __name__ == "__main__":
    xmlfilepath     = os.path.join(VOCdevkit_path, 'Annotations')
    print("xmlfilepath:" + xmlfilepath)
    xmlfiles        = os.listdir(xmlfilepath)

    jpgFilePath     = os.path.join(VOCdevkit_path, 'JPEGImages')
    print("jpgFilePath:" + jpgFilePath)
    jpgFiles        = os.listdir(jpgFilePath)

    #查找文件
    for filename in jpgFiles:
        shortName = os.path.splitext(filename)[0]
        xmlfilename = shortName+".xml"
        if xmlfilename not in xmlfiles:
            #删除没有标签的文件
            jpgFile = os.path.join(jpgFilePath,shortName+".jpg")
            if (os.path.exists(jpgFile)):
                os.remove(jpgFile)
                print("delete " + jpgFile)

        

    